import 'package:flutter/material.dart';
import 'dart:convert';
import 'package:qaun_ni_dev/utils/request.dart';
import 'package:qaun_ni_dev/utils/toast.dart';
import 'package:qaun_ni_dev/model/header_portrait_model.dart';


class HeaderPortraitProvider with ChangeNotifier {
  int page = 1;
  List<PortraitData> headerPortraitData = [];

  getHeaderPortraitList(context) async{
    page = 1;
    headerPortraitData = [];
    var formData = {
      'currentPage': page,
    };
    await requestPost(context, '/check/avatarList',formData: formData).then((value){
      var res = json.decode(value.toString());
      var tempData = HeaderPortraitModel.fromJson(res);
      print('aaaaaaa>>>>>>>>>>>>>>>>>>>>>>${tempData.data.length}');
      if(tempData.data.length > 0) {
        headerPortraitData = tempData.data;
//        print('headerPortraitData>>>>>>>>>>>${headerPortraitData[0].uid}');
      } else {
        return Toast.toast(context,msg: '暂无数据');
      }
      notifyListeners();
    });
  }

  getHeaderPortraitMoreList(context) async{
    page++;
    var formData = {
      'currentPage': page,
    };
    await requestPost(context, '/check/avatarList',formData: formData).then((value){
      var res = json.decode(value.toString());
      var tempData = HeaderPortraitModel.fromJson(res);
      if(tempData.code == 200) {
        var tempMoreData = tempData.data;
        if(tempMoreData.length > 0 ) {
          headerPortraitData.addAll(tempMoreData);
        } else {
          Toast.toast(context,msg: '已经没有更多数据了哦！');
        }
      }
    });
    notifyListeners();
  }

  isPassCheck(context,formData)async {
    await requestPost(context, '/check/avatarCheck',formData: formData).then((value) {
      var res = json.decode(value.toString());
      if (res['code'] == 200) {
        Toast.toast(context,msg: '操作成功');
        getHeaderPortraitList(context);
      } else {
        Toast.toast(context,msg: '操作失败了');
        getHeaderPortraitList(context);
      }
    });
  }

}

